package com.code.zg.news.utils;

import rx.Observable;
import rx.subjects.PublishSubject;
import rx.subjects.SerializedSubject;

/**
 * Created by zhanggang on 2017/2/28.
 */

public class RxBus {
    private final SerializedSubject<Object, Object> bus;

    public static RxBus getDefault(){
        return RxBusHolder.instance;
    }
    private static class RxBusHolder{
        private static final  RxBus instance=new RxBus();
    }
    private RxBus(){
         bus = new SerializedSubject<>(PublishSubject.create());
    }
    public void post(Object o){
        bus.onNext(o);
    }
    public <T>Observable <T>toObservable(Class<T>eventType){
        return bus.ofType(eventType);
    }

}
